package com.hub.videobrowsdownload

import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.os.Build
import android.webkit.WebView
import androidx.lifecycle.ViewModelProvider
import com.forest.download.helper.Default
import java.util.concurrent.TimeoutException


open class BrowsApplication : Application() {
    companion object {
        lateinit var context: Application

        val browsMyViewModel by lazy {
            ViewModelProvider.AndroidViewModelFactory(context).create(BrowsMyViewModel::class.java)
        }


    }

    override fun onCreate() {
        super.onCreate()

        Default.context = this
        context = this

        browsMyViewModel.onCreate(this)

        Thread.setDefaultUncaughtExceptionHandler { thread0, throwable0 ->
            if (thread0.name != "FinalizerWatchdogDaemon" || throwable0 !is TimeoutException) {
                thread0.uncaughtExceptionHandler?.uncaughtException(thread0, throwable0)
            }
        }

        if (Build.VERSION.SDK_INT >= 26) {
            val notificationChannel0 = NotificationChannel("downloadChannel", "download Channel", 4)
            (this.getSystemService(NotificationManager::class.java) as NotificationManager).createNotificationChannel(
                notificationChannel0
            )
        }
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                if (packageName != getProcessName()) {
                    WebView.setDataDirectorySuffix(getProcessName())
                }
            }
        } catch (e: Exception) {

        }
    }
}